package cn.jasonone.util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {
	private static String url;
	private static String username;
	private static String password;

	static {
		InputStream is = DBUtil.class.getResourceAsStream("/jdbc.properties");
		Properties p = new Properties();
		try {
			p.load(is);
			// 加载驱动
			Class.forName(p.getProperty("jdbc.driverClassName"));
			url = p.getProperty("jdbc.url");
			username = p.getProperty("jdbc.username");
			password = p.getProperty("jdbc.password");
		} catch (IOException | ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() throws SQLException {
		return DriverManager.getConnection(url, username, password);
	}
}
